<template>
  <div class="add-suppliers">
    <el-breadcrumb separator="/">
      <el-breadcrumb-item>系统设置</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/index/supply_setting' }">供应设置</el-breadcrumb-item>
      <el-breadcrumb-item>新增供应商</el-breadcrumb-item>
    </el-breadcrumb>
    <el-form label-width="200px"
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm">
      <div class="information-page">
        <el-form-item class="information-title">
          <h1>
            <span style="padding-right:15px">支付类型选择</span>
            <el-radio :label="1"
              v-model="ruleForm.payType">好客云平台支付</el-radio>
            <el-radio :label="2"
              v-model="ruleForm.payType">开通易宝支付</el-radio>
          </h1>
        </el-form-item>
        <el-form-item class="information-title">
          <h1>公司基础信息</h1>
        </el-form-item>
        <div class="basic-information">
          <div class="information-left-page">
            <el-form-item label="公司全称"
              prop="supplierBaseInfo.company">
              <el-input v-model="ruleForm.supplierBaseInfo.company"
                placeholder="请输入公司名称"></el-input>
            </el-form-item>
            <el-form-item label="公司简称"
              prop="supplierBaseInfo.merShortName">
              <el-input v-model="ruleForm.supplierBaseInfo.merShortName"
                placeholder="请输入公司简称"></el-input>
            </el-form-item>
            <el-form-item label="公司类型"
              prop="supplierBaseInfo.type">
              <el-select v-model="ruleForm.supplierBaseInfo.type"
                placeholder="请选择公司类型">
                <el-option label="企业"
                  :value="0"></el-option>
                <el-option label="旅行社"
                  :value="1"></el-option>
                <el-option label="酒店"
                  :value="2"></el-option>
                <el-option label="第三方"
                  :value="3"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="证件类型"
              v-if="ruleForm.payType==2"
              prop="supplierBaseInfo.merCertType">
              <el-select v-model="ruleForm.supplierBaseInfo.merCertType"
                placeholder="请选择证件类型">
                <el-option label="营业执照"
                  :value="1"></el-option>
                <el-option label="统一社会信用代码证"
                  :value="2"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="开户许可证编号"
              prop="supplierBaseInfo.accountLicense"
              v-if="ruleForm.payType==2">
              <el-input placeholder="请输入开户许可证编号"
                v-model="ruleForm.supplierBaseInfo.accountLicense"></el-input>
            </el-form-item>
            <el-form-item label="组织机构代码证"
              prop="supplierBaseInfo.orgCode"
              v-if="ruleForm.payType==2 && ruleForm.supplierBaseInfo.merCertType==1">
              <el-input placeholder="请输入组织机构代码证"
                v-model="ruleForm.supplierBaseInfo.orgCode"></el-input>
            </el-form-item>
            <el-form-item label="公司法人"
              prop="supplierBaseInfo.legalName"
              v-if="ruleForm.payType==2">
              <el-input placeholder="请输入公司法人"
                v-model="ruleForm.supplierBaseInfo.legalName"></el-input>
            </el-form-item>
            <el-form-item label="区域"
              prop="supplierBaseInfo.area"
              class="area">
              <el-cascader :options="cities"
                placeholder="请选择公司区域"
                :props="{ value: 'cityid', label: 'city', children: 'citiess' }"
                v-model="city"
                filterable>
              </el-cascader>
            </el-form-item>
            <el-form-item label="邮编">
              <el-input v-model="ruleForm.supplierBaseInfo.postcode"
                placeholder="请输入邮编"></el-input>
            </el-form-item>
            <el-form-item label="传真">
              <el-input v-model="ruleForm.supplierBaseInfo.fax"
                placeholder="请输入公司传真"></el-input>
            </el-form-item>
            <el-form-item label="公司简介">
              <el-input type="textarea"
                v-model="ruleForm.supplierBaseInfo.profile"
                :rows="6"
                placeholder="请输入公司简介"></el-input>
            </el-form-item>
          </div>
          <div class="information-right-page">
            <el-form-item label="公司logo">
              <UploadPic v-model="ruleForm.supplierBaseInfo.logo" />
            </el-form-item>
            <el-form-item label="关联酒店"
              prop="supplierBaseInfo.hotelId">
              <el-select v-model="ruleForm.supplierBaseInfo.hotelId">
                <el-option v-for="item in hotelNames"
                  :key="item.id"
                  :value="item.id"
                  :label="item.name"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="证件编号"
              prop="supplierBaseInfo.merCertNo"
              v-if="ruleForm.payType==2">
              <el-input type="text"
                v-model="ruleForm.supplierBaseInfo.merCertNo"
                placeholder="请输入证件编号"></el-input>
            </el-form-item>
            <el-form-item label="税务登记证编号"
              prop="supplierBaseInfo.taxRegistCert"
              v-if="ruleForm.payType==2 &&  ruleForm.supplierBaseInfo.merCertType==1">
              <el-input type="text"
                v-model="ruleForm.supplierBaseInfo.taxRegistCert"
                placeholder="请输入税务登记证编号"></el-input>
            </el-form-item>
            <el-form-item label="组织机构代码证有效期类型"
              prop="supplierBaseInfo.isOrgCodeLong"
              required
              v-if="ruleForm.payType==2 &&  ruleForm.supplierBaseInfo.merCertType==1">
              <el-select v-model="ruleForm.supplierBaseInfo.isOrgCodeLong">
                <el-option :value="1"
                  label="长期有效">
                </el-option>
                <el-option :value="2"
                  label="非长期有效">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item prop="supplierBaseInfo.orgCodeExpiry"
              label="组织机构代码证有效期"
              v-if="ruleForm.supplierBaseInfo.isOrgCodeLong==2">
              <el-date-picker v-model="ruleForm.supplierBaseInfo.orgCodeExpiry"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择有效期日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="法人身份证"
              prop="supplierBaseInfo.legalIdCard">
              <el-input placeholder="请输入法人身份证"
                v-model="ruleForm.supplierBaseInfo.legalIdCard"></el-input>
            </el-form-item>
            <el-form-item label="详细地址"
              prop="supplierBaseInfo.address">
              <el-input v-model="ruleForm.supplierBaseInfo.address"
                placeholder="请输入公司详细地址"></el-input>
            </el-form-item>
            <el-form-item label="公司电话"
              prop="supplierBaseInfo.landline">
              <el-input v-model="ruleForm.supplierBaseInfo.landline"
                placeholder="请输入公司电话号码"></el-input>
            </el-form-item>

            <el-form-item label="公司网址">
              <el-input v-model="ruleForm.supplierBaseInfo.url"
                placeholder="请输入公司网址"></el-input>
            </el-form-item>
          </div>

        </div>
        <el-form-item class="information-title"
          v-if="ruleForm.payType==2">
          <h1>资质影印件（必选）</h1>
        </el-form-item>
        <div class="basic-information"
          v-if="ruleForm.payType==2">
          <div>
            <el-form-item label="资质影印件"
              required>
              <ul class="picture-list">
                <li v-for="(item,index) in ruleForm.fileInfos"
                  :key="item.payType">
                  <UploadPic v-model="item.url" />
                  <p style="text-align:center;width:128px">{{fileTitle[index]}}</p>
                </li>
              </ul>
            </el-form-item>
          </div>
        </div>
        <el-form-item class="information-title">
          <h1>财务信息</h1>
        </el-form-item>
        <div class="financial-information">
          <div class="information-left-page">
            <el-form-item label="开户省市"
              prop="financeInfo.bankCity">
              <el-cascader :options="citys"
                placeholder="请选择公司区域"
                :props="{ value: 'cityid', label: 'city', children: 'citiess' }"
                v-model="province_city"
                filterable
                @change="selectProvince_city">
              </el-cascader>
            </el-form-item>
            <el-form-item label="开户银行"
              v-if="ruleForm.financeInfo.bankCity"
              prop="financeInfo.bankId">
              <el-select v-model="ruleForm.financeInfo.bankId"
                @change="selsetBank"
                :clearable="false"
                filterable
                placeholder="请输入开户银行">
                <el-option v-for="item in banksList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>

            <el-form-item label="银行账号"
              prop="financeInfo.banksAccount">
              <el-input v-model="ruleForm.financeInfo.banksAccount"
                placeholder="请输入公司银行账号"></el-input>
            </el-form-item>
            <el-form-item label="纳税人识别号">
              <el-input v-model="ruleForm.financeInfo.taxCode"
                placeholder="请输入纳税人识别号"></el-input>
            </el-form-item>

          </div>
          <div class="information-right-page">
            <el-form-item label="开户支行"
              v-if="ruleForm.financeInfo.bankId"
              prop="financeInfo.bankCode">
              <el-select v-model="ruleForm.financeInfo.bankCode"
                @change="selsetBranchBank"
                clearable
                filterable
                placeholder="请输入开户支行名称">
                <el-option v-for="item in branchBankList"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code">
                </el-option>
              </el-select>
              <!-- <el-input v-model="ruleForm.financeInfo.branch"
                placeholder="请输入开户支行名称"></el-input> -->
            </el-form-item>
            <el-form-item label="结算方式"
              prop="financeInfo.clearingMode"
              v-if="ruleForm.payType==1">
              <el-select v-model="ruleForm.financeInfo.clearingMode"
                placeholder="请选择结算方式"
                @change="modeChange">
                <el-option label="日结"
                  :value="0"></el-option>
                <el-option label="周结"
                  :value="1"></el-option>
                <el-option label="月结"
                  :value="2"></el-option>
                <el-option label="半月结"
                  :value="3"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="结算时间" 
              prop="financeInfo.clearingTime"
              v-if="ruleForm.financeInfo.clearingMode !== 0&&ruleForm.payType==1 ">
              <el-select v-model="ruleForm.financeInfo.clearingTime"
                placeholder="请选择结算时间"
                v-if="ruleForm.financeInfo.clearingMode === 1">
                <el-option :label="item.label"
                  :key="item.id"
                  :value="item.value"
                  v-for="item in timeData">{{item.label}}</el-option>
              </el-select>
              <el-select v-model="ruleForm.financeInfo.clearingTime"
                placeholder="请选择结算时间"
                v-if="ruleForm.financeInfo.clearingMode === 2">
                <el-option :label="item"
                  :value="item"
                  v-for="item in timeData"
                  :key="item.id">{{item}}</el-option>
              </el-select>
              <div class="time-style"
                v-if="ruleForm.financeInfo.clearingMode === 3">
                <div class="items">
                  <el-form-item>
                    <el-select v-model="ruleForm.financeInfo.clearingTime"
                      placeholder="请选择半月结算时间">
                      <el-option :label="item"
                        v-for="item in timeData"
                        :key="item.id"
                        :value="item">{{item}}</el-option>
                    </el-select>
                  </el-form-item>

                </div>
                <div class="item">
                  <el-form-item prop="financeInfo.clearingTimeTwo">
                    <el-select v-model="ruleForm.financeInfo.clearingTimeTwo"
                      placeholder="请选择半月结算时间">
                      <el-option :label="item"
                        v-for="item in timeData"
                        :key="item.id"
                        :value="item">{{item}}</el-option>
                    </el-select>
                  </el-form-item>

                </div>
              </div>
            </el-form-item>
            <el-form-item label="结算方式"
              v-if="ruleForm.payType==2">
              <span>易宝支付</span>
            </el-form-item>
            <el-form-item label="发票抬头">
              <el-input v-model="ruleForm.financeInfo.invoice"
                placeholder="请输入发票抬头"></el-input>
            </el-form-item>
          </div>
        </div>
        <el-form-item class="information-title">
          <h1>合作信息</h1>
        </el-form-item>
        <div class="service-support">
          <div class="information-left-page">
            <el-form-item label="签约人"
              prop="contractInfo.contractor">
              <el-input v-model="ruleForm.contractInfo.contractor"
                placeholder="请输入签约人姓名"></el-input>
            </el-form-item>
            <el-form-item label="联系人"
              prop="contractInfo.userName">
              <el-input v-model="ruleForm.contractInfo.userName"
                placeholder="请输入联系人"></el-input>
            </el-form-item>
            <el-form-item label="联系人邮箱">
              <el-input v-model="ruleForm.contractInfo.email"
                placeholder="请输入联系人"></el-input>
            </el-form-item>
            <el-form-item label="QQ">
              <el-input v-model="ruleForm.contractInfo.qq"
                placeholder="请输入QQ号码"></el-input>
            </el-form-item>
            <el-form-item label="角色"
              required>
              <el-select v-model="roleName"
                placeholder="请选择角色">
                <el-option :label="roleName"
                  :value="roleName"></el-option>
              </el-select>
            </el-form-item>

          </div>
          <div class="information-right-page">
            <el-form-item label="签约人手机号"
              prop="contractInfo.contractorPhone">
              <el-input v-model="ruleForm.contractInfo.contractorPhone"
                type="number"
                placeholder="请输入签约人手机号码"></el-input>
            </el-form-item>

            <el-form-item label="联系人手机"
              prop="contractInfo.userPhone">
              <el-input v-model="ruleForm.contractInfo.userPhone"
                type="number"
                placeholder="请输入联系人手机"></el-input>
            </el-form-item>
            <el-form-item label="职位">
              <el-input v-model="ruleForm.contractInfo.position"
                placeholder="请输入联系人职位"></el-input>
            </el-form-item>
            <el-form-item label="管理账号"
              prop="contractInfo.account">
              <el-input v-model="ruleForm.contractInfo.account"
                placeholder="请输入管理账号名称"></el-input>
            </el-form-item>

          </div>
        </div>
        <el-form-item label="合作模式"
          required>
          <el-radio-group v-model="ruleForm.modeId">
            <el-radio v-for="item in modeList"
              :key="item.id"
              :label="item.id">{{item.name}}</el-radio>
          </el-radio-group>
        </el-form-item>
      </div>
      <div class="information-btn">
        <el-form-item>
          <el-button type="primary"
            @click="saveForm('ruleForm')">保存</el-button>
          <el-button @click="back">取消</el-button>
        </el-form-item>
      </div>
    </el-form>
  </div>
</template>
<script>
import {
  getRoleList,
  addSuppliers,
  getHotelsList,
  logo,
  getBankList,
  getBranchBankList,
  getSuppliersInformation,
  updateSuppliers
} from "../../../public/js/setting";
import UploadPic from "@/components/common/uploadPic";
import { getModeList } from "@/public/js/mode";
import axios from "axios";
const ButtonFooter = () => import("@/components/common/ButtonFooter");
const cityData = require("@/data/editCities.json");
const provinces_city = require("@/data/cities.json");
export default {
  name: "CompanyInformation",
  data() {
    return {
      id: "",
      isOrgCodeLong: false,
      roleName: "供应商管理员",
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7;
        }
      },
      branchBankList: [],
      modeList: [],
      region: "",
      timeWeek: "",
      fileList: [],
      contractFile: [],
      cities: cityData.provincesEntities,
      citys: provinces_city.provincesEntities,
      province_city: [],
      url: "",
      headBankCode: "",
      fileTitle: [
        "法人身份证正面",
        "法人身份证反面",
        "营业执照",
        "税务登记证",
        "组织机构代码证",
        "统一社会信用代码证",
        "银行开户许可证"
      ],
      ruleForm: {
        payType: 1,
        supplierBaseInfo: {
          company: "",
          merShortName: "",
          type: "",
          logo: "",
          area: "",
          hotelId: "",
          address: "",
          postcode: "",
          landline: "",
          fax: "",
          url: "",
          profile: "",
          orgCodeExpiry: "", // 非长期有效截止日期
          merCertType: 1, //证件类型 1.营业执照 2.统一
          merCertNo: "",
          accountLicense: "",
          taxRegistCert: "",
          orgCode: "",
          isOrgCodeLong: 1,
          legalName: "",
          legalIdCard: ""
        },
        fileInfos: [
          {
            type: 1,
            url: ""
          },
          {
            type: 2,
            url: ""
          },
          {
            type: 3,
            url: ""
          },
          {
            type: 4,
            url: ""
          },
          {
            type: 5,
            url: ""
          },
          {
            type: 6,
            url: ""
          },
          {
            type: 7,
            url: ""
          }
        ],
        financeInfo: {
          bankId: "",
          banks: "",
          branch: "",
          bankCode: "",
          banksAccount: "",
          clearingMode: 0,
          clearingTime: "",
          clearingTimeTwo: "",
          taxCode: "",
          invoice: "",
          bankProvince: "",
          bankCity: ""
        },
        contractInfo: {
          contractor: "",
          contractorPhone: "",
          userName: "",
          userPhone: "",
          qq: "",
          position: "",
          account: "",
          roleId: "",
          email: ""
        },
        modeId: ""
      },
      banksList: [],
      rules: {
        "supplierBaseInfo.company": [
          { required: true, message: "请输入公司全称", trigger: "blur" }
        ],
        "supplierBaseInfo.merShortName": [
          { required: true, message: "请输入公司简称", trigger: "blur" }
        ],
        "supplierBaseInfo.type": [
          { required: true, message: "请选择公司类型", trigger: "change" }
        ],
        "supplierBaseInfo.area": [
          { required: true, message: "请选择公司区域", trigger: "change" }
        ],
        "supplierBaseInfo.hotelId": [
          { required: true, message: "请选择关联酒店", trigger: "change" }
        ],
        "supplierBaseInfo.landline": [
          { required: true, message: "请输入公司电话", trigger: "blur" }
        ],
        "supplierBaseInfo.address": [
          { required: true, message: "请输入公司详细地址", trigger: "blur" }
        ],
        "financeInfo.bankId": [
          { required: true, message: "请选择开户银行", trigger: "blur" }
        ],
        "supplierBaseInfo.merCertType": [
          { required: true, message: "请选择证件类型", trigger: "blur" }
        ],
        "supplierBaseInfo.merCertNo": [
          { required: true, message: "请输入证件编号", trigger: "blur" }
        ],
        "supplierBaseInfo.orgCode": [
          { required: true, message: "请输入组织机构代码证", trigger: "blur" }
        ],
        "supplierBaseInfo.accountLicense": [
          { required: true, message: "请输入开户许可证编号", trigger: "blur" }
        ],
        "supplierBaseInfo.taxRegistCert": [
          { required: true, message: "请输入税务登记证编号", trigger: "blur" }
        ],
        "supplierBaseInfo.legalName": [
          { required: true, message: "请输入公司法人", trigger: "blur" }
        ],
        "supplierBaseInfo.legalIdCard": [
          { required: true, message: "请输入法人身份证", trigger: "blur" }
        ],

        "financeInfo.clearingTime": [
          { required: true, message: "请选择结算时间", trigger: "change" }
        ],
        "financeInfo.bankCode": [
          { required: true, message: "请选择开户支行", trigger: "blur" }
        ],
        "financeInfo.banksAccount": [
          { required: true, message: "请输入银行账号", trigger: "blur" }
        ],
        "financeInfo.clearingMode": [
          { required: true, message: "请选择结算方式", trigger: "change" }
        ],
        "supplierBaseInfo.orgCodeExpiry": [
          { required: true, message: "请选择有效日期", trigger: "change" }
        ],
        "financeInfo.clearingTimeTwo": [
          { required: true, message: "请选择半月结算时间", trigger: "change" }
        ],
        "financeInfo.bankCity": [
          { required: true, message: "请选择开户省市", trigger: "change" }
        ],
        "contractInfo.contractor": [
          { required: true, message: "请输入签约人", trigger: "blur" }
        ],
        "contractInfo.contractorPhone": [
          { required: true, message: "请输入签约人手机号", trigger: "blur" }
        ],
        "contractInfo.userName": [
          { required: true, message: "请输入联系人", trigger: "blur" }
        ],
        "contractInfo.userPhone": [
          { required: true, message: "请输入联系人手机号", trigger: "blur" }
        ],
        "contractInfo.account": [
          { required: true, message: "请输入管理账号", trigger: "blur" }
        ]
      },
      clearingTime: true,
      timeData: [
        { label: "周日", value: 7 },
        { label: "周一", value: 1 },
        { label: "周二", value: 2 },
        { label: "周三", value: 3 },
        { label: "周四", value: 4 },
        { label: "周五", value: 5 },
        { label: "周六", value: 6 }
      ],
      city: [],
      postData: {},
      roleData: [],
      file: "",
      hotelNames: [],
      oldPath: ""
    };
  },
  created() {
    getRoleList().then(res => {
      if (res.data.errCode === 0) this.roleData = res.data.roleEntities;
    });
    this._getModeList();
    this._getBankList();
    this.id = this.$route.query.id ? this.$route.query.id : "";
    this._getHotelsList();
    if (this.id) {
      this._getSuppliersInformation();
    } else {
      this.ruleForm = {
        payType: 1,
        supplierBaseInfo: {
          company: "",
          merShortName: "",
          type: "",
          logo: "",
          area: "",
          hotelId: "",
          address: "",
          postcode: "",
          landline: "",
          fax: "",
          url: "",
          profile: "",
          orgCodeExpiry: "", // 非长期有效截止日期
          merCertType: 1, //证件类型 1.营业执照 2.统一
          merCertNo: "",
          accountLicense: "",
          taxRegistCert: "",
          orgCode: "",
          isOrgCodeLong: 1,
          legalName: "",
          legalIdCard: ""
        },
        fileInfos: [
          {
            type: 1,
            url: ""
          },
          {
            type: 2,
            url: ""
          },
          {
            type: 3,
            url: ""
          },
          {
            type: 4,
            url: ""
          },
          {
            type: 5,
            url: ""
          },
          {
            type: 6,
            url: ""
          },
          {
            type: 7,
            url: ""
          }
        ],
        financeInfo: {
          bankId: "",
          banks: "",
          branch: "",
          bankCode: "",
          banksAccount: "",
          clearingMode: 0,
          clearingTime: "",
          clearingTimeTwo: "",
          taxCode: "",
          invoice: "",
          bankProvince: "",
          bankCity: ""
        },
        contractInfo: {
          contractor: "",
          contractorPhone: "",
          userName: "",
          userPhone: "",
          qq: "",
          position: "",
          account: "",
          roleId: "",
          email: ""
        },
        modeId: ""
      };
    }
  },
  methods: {
    //获取供应商信息
    _getSuppliersInformation() {
      getSuppliersInformation({ id: this.id }).then(res => {
        let {
          contractInfo,
          fileInfos,
          financeInfo,
          supplierBaseInfo,
          id,
          modeId,
          payType
        } = res.data;
        this.city = supplierBaseInfo.areas;
        this.ruleForm = {
          contractInfo,
          fileInfos,
          financeInfo,
          supplierBaseInfo,
          id,
          modeId,
          payType
        };

        getBranchBankList({
          headBankCode: financeInfo.banksCode,
          provinceCode: financeInfo.bankProvince,
          cityCode: financeInfo.bankCity
        }).then(res => {
          this.branchBankList = res.data.branchBankList;
        });
        if (!this.ruleForm.fileInfos.length) {
          this.ruleForm.fileInfos = [
            {
              type: 1,
              url: ""
            },
            {
              type: 2,
              url: ""
            },
            {
              type: 3,
              url: ""
            },
            {
              type: 4,
              url: ""
            },
            {
              type: 5,
              url: ""
            },
            {
              type: 6,
              url: ""
            },
            {
              type: 7,
              url: ""
            }
          ];
        }

        if (financeInfo.bankProvince == financeInfo.bankCity) {
          this.province_city = [financeInfo.bankCity + ""];
        } else {
          this.province_city = [
            financeInfo.bankProvince + "",
            financeInfo.bankCity + ""
          ];
        }
      });
    },
    //获取开户银行列表
    _getBankList() {
      getBankList().then(res => {
        this.banksList = res.data.banks;
      });
    },
    // 获取酒店列表
    _getHotelsList() {
      getHotelsList({
        id: this.id
      }).then(res => {
        this.hotelNames = res.data.hotelNames;
      });
    },
    //获取mode
    _getModeList() {
      getModeList().then(res => {
        this.modeList = res.data.modes;
        this.ruleForm.modeId = this.modeList[0].id;
      });
    },
    addServiceInpput() {
      this.ruleForm.contractInfo.suppliersContracts.push({
        room: "",
        floorPrice: "",
        roomAmount: "",
        breakfast: ""
      });
    },
    //选择开户银行
    selsetBank(val) {
      this.banksList.forEach(item => {
        if (item.id == val) {
          this.ruleForm.financeInfo.banks = item.name;
          this.headBankCode = item.code;
        }
      });
      this._getBranchBankList();
    },
    //获取支行数据
    _getBranchBankList() {
      let provinceCode,
        cityCode = "";
      provinceCode = this.ruleForm.financeInfo.bankProvince;
      cityCode = this.ruleForm.financeInfo.bankCity;
      if (provinceCode && this.headBankCode) {
        this.ruleForm.financeInfo.bankCode = "";
        getBranchBankList({
          headBankCode: this.headBankCode,
          provinceCode,
          cityCode
        }).then(res => {
          console.log("res", res);
          this.branchBankList = res.data.branchBankList;
        });
      }
    },
    deleteInput(index) {
      this.ruleForm.contractInfo.suppliersContracts.splice(index, 1);
    },
    sendChange(e) {
      var reader = new FileReader();
      reader.readAsDataURL(e.file);
      reader.onload = e => {
        let photoPath = e.target.result;
        logo({
          nowPath: photoPath,
          oldPath: this.oldPath
        }).then(res => {
          this.oldPath = res.data.path;
        });
      };
    },
    modeChange(value) {
      if (value === 0) {
        this.clearingTime = false;
      } else if (value === 1) {
        this.clearingTime = true;
        this.timeData = [
          { label: "周日", value: 7 },
          { label: "周一", value: 1 },
          { label: "周二", value: 2 },
          { label: "周三", value: 3 },
          { label: "周四", value: 4 },
          { label: "周五", value: 5 },
          { label: "周六", value: 6 }
        ];
      } else {
        this.timeData = 31;
        this.clearingTime = true;
      }
    },
    //开户省市
    selectProvince_city(val) {
      if (val.length > 1) {
        this.ruleForm.financeInfo.bankCity = val[1];
        this.ruleForm.financeInfo.bankProvince = val[0];
      } else {
        this.ruleForm.financeInfo.bankCity = val[0];
        this.ruleForm.financeInfo.bankProvince = val[0];
      }
      this._getBranchBankList();
    },
    //支行
    selsetBranchBank(val) {
      this.branchBankList.forEach(item => {
        if (item.code == val) {
          this.ruleForm.financeInfo.branch = item.name;
        }
      });
    },
    handleRemove(file, fileList) {
      this.fileList = fileList;
      if (this.fileList.length) {
        if (this.fileList.length > 0) this.files = true;
      } else {
        this.files = false;
      }
    },
    handleExceed(files, fileList) {
      this.$message.warning(
        `当前限制选择 3 个文件，本次选择了 ${
          files.length
        } 个文件，共选择了 ${files.length + fileList.length} 个文件`
      );
    },
    saveForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          //证件图片文件验证
          if (this.ruleForm.payType == 2) {
            let fileInfos = this.ruleForm.fileInfos;
            for (let i of fileInfos) {
              if (i.url == "") {
                this.$message.error("请上传完整的资质影印件");
                return false;
              }
            }
          }
          this.ruleForm.supplierBaseInfo.area = parseInt(
            this.city[this.city.length - 1]
          );
          delete this.ruleForm.supplierBaseInfo.areas;
          if (this.id) {
            updateSuppliers(this.ruleForm).then(res => {
              if (res.data.errCode === 0) {
                this.$message.success("修改成功");
                this.$router.go(-1);
              }
            });
          } else {
            addSuppliers(this.ruleForm).then(res => {
              if (res.data.errCode === 0) {
                this.$alert(
                  "供应商名称: " +
                    this.ruleForm.supplierBaseInfo.company +
                    "  密码: " +
                    888888,
                  "提示",
                  {
                    confirmButtonText: "确定",
                    callback: action => {
                      this.$message.success("添加供应商成功");
                      this.$router.go(-1);
                    }
                  }
                );
              }
            });
          }
        } else {
          return false;
        }
      });
    },
    back() {
      this.$router.go(-1);
    },
    downloadChange(req) {
      this.file.name = req.file.name;
      getQiniuPublicToken(this)
        .then(res => {
          if (res.data.errCode === 0) return res.data.qnInfo;
        })
        .then(res => {
          const formData = new FormData();
          formData.append("file", req.file);
          formData.append("token", res);
          formData.append("key", window.commo.uuid + "_" + req.file.name);
          this.fileList = [];
          updateQiniu(formData).then(res => {
            if (res.status === 200) {
              this.fileList.push({
                name: res.data.key,
                url: window.commo.qiniuImageUrl + res.data.key
              });
              if (this.fileList.length) {
                if (this.fileList.length > 0) this.files = true;
              } else {
                this.files = false;
              }
            }
          });
        });
    },
    downloadFilesAdd(file, filelist) {
      this.file = file;
    }
  },
  components: {
    ButtonFooter,
    UploadPic
  }
};
</script>
<style lang="scss" scoped>
.time-style {
  display: flex;
  .item,
  .items {
    flex: 1;
  }
  .items {
    margin-right: 10px;
  }
}
.download-file {
  position: absolute;
  top: 0;
  left: 30%;
  color: #409eff;
  z-index: 9999;
  font-size: 12px;
}
.add-suppliers {
  margin-bottom: 63px;
  .el-form {
    margin-top: 10px;
    background-color: white;

    .information-page {
      padding: 20px;
      .basic-information,
      .financial-information,
      .service-support {
        overflow: hidden;
        .information-left-page {
          width: 47%;
          float: left;
        }
        .information-right-page {
          width: 47%;
          float: right;
        }
      }
      .basic-information {
        .information-left-page {
          .information-title {
            .el-form-item__content {
              margin-left: 0 !important;
            }
          }
          .area {
            text-align: left;
          }
        }
      }
      h1 {
        color: #6d2377;
        text-align: left;
      }
    }
  }
  .picture-list {
    display: flex;
    text-align: center;
  }
}

.information-left {
  width: 50%;
  float: left;
}
.information-right {
  width: 50%;
  float: left;
}
.service_person {
  width: 100%;
  height: 40px;
  background-color: #eef1f9;
  margin-bottom: 10px;
  .item-first {
    width: 40% !important;
  }
  .item {
    width: 20%;
    float: left;
    text-align: left;
    label {
      font-size: 12px;
      margin-left: 10px;
    }
  }
}
.service-input {
  margin-bottom: 10px;
  display: inline-block;
  position: relative;
  .item-input {
    width: 40% !important;
  }
  .input-delete {
    position: absolute;
    top: 0;
    right: -25px;
  }
  .el-input {
    width: 20%;
    float: left;
    text-align: left;
    .el-input__inner {
      width: 90%;
    }
  }
  .last-input {
    .el-input__inner {
      width: 100%;
    }
  }
}
.service-btn {
  text-align: left;
}
.el-select,
.el-cascader {
  display: block;
}

.el-date-editor.el-input,
.el-date-editor.el-input__inner {
  width: 100%;
}

.information-left-page {
  .el-upload {
    display: block;
    text-align: left;
    .el-button + .el-button {
      margin-left: 30%;
    }
  }
}
.el-upload-list {
  position: absolute;
  top: 0;
  left: 0;
  width: 30%;
}
</style>
